var wtt;

$(document).ready(function() {

	$(".wishlist_container:not(.wishlist_container_eu) .wishlist_item_container").live("click",function(){
	
		slot=$(this).parent().attr('id').split('-');
		$.post("ajaxload.php",{page: "modules/wishlist/ajax.php", action: "enlever_item", idPlayer: idPlayer, idItem: $(this).attr('id'), slot: slot[0], n: slot[1] });
		$(this).remove();
	});

	$(".wishlist_slot_titre").each(function(){
		t=0;
		l=0;
		c=$(this).html();
		$(this).html("");
		$(this).prepend("<div class='wishlist_slot_titre_shadow' style='top: "+t+"px; left: "+l+"px; color: #FFFFFF;'>"+c+"</div>")
		.prepend("<div class='wishlist_slot_titre_shadow' style='top: "+(t-1)+"px; left: "+(l-1)+"px;'>"+c+"</div>")
		.prepend("<div class='wishlist_slot_titre_shadow' style='top: "+(t-1)+"px; left: "+(l+1)+"px;'>"+c+"</div>")
		.prepend("<div class='wishlist_slot_titre_shadow' style='top: "+(t+1)+"px; left: "+(l-1)+"px;'>"+c+"</div>")
		.prepend("<div class='wishlist_slot_titre_shadow' style='top: "+(t+1)+"px; left: "+(l+1)+"px;'>"+c+"</div>")
	});

	$(".wishlist_droppable").each(function(){
		tmp=$(this).attr('id').split('-');
		str='';
		for(i=2; i<tmp.length; i++){
			str+='.wishlist_item_slot_'+tmp[i]+', ';
		}
		//alert(str);
		$(this).droppable({
			activeClass: 'wishlist_container_active',
			hoverClass: 'wishlist_container_hover',
			accept: str,
			drop: function(event,ui){
				$that=$(this);
				$(this).empty();
				ui.draggable.clone().fadeOut("fast", function(){
					$(this).appendTo($that)
					.fadeIn("fast")
					.draggable('disable');
				});
				slot=$(this).attr('id').split('-');
				$.post("ajaxload.php",{page: "modules/wishlist/ajax.php", action: "ajouter_item", idPlayer: idPlayer, idItem: ui.draggable.attr('id'), slot: slot[0], n: slot[1] });
			}
		});		
	});
	
	wishlist_get_item();
});

function wishlist_get_item(){
	search=document.getElementById('wishlist_search').value;
	if(isNaN(search)||(search=='')){
		$('#wishlist_items_list').html("<div style='text-align: center; padding-top: 30px; color: #FFFFFF;'>Recherche...</div>");
		$.post(
			"ajaxload.php",
			{ page: 'modules/wishlist/ajax.php', action: 'recherche', str: search},
			function(data){
				//alert(data);
				$('#wishlist_items_list').html(data);
				$('#wishlist_items_list .wishlist_item_container').draggable({
					zIndex:100,
					opacity: 0.80,
					revert:false,
					helper: "clone"
				}).addClass('pointer');
			},
			'html'
		);
	}else{
		$('#wishlist_recherche .wishlist_container').html("Recherche...");
		$.post(
			"ajaxload.php",
			{ page: 'modules/wishlist/ajax.php', action: 'get item', itemId: search},
			function(data){
				$('#wishlist_recherche .wishlist_container').html(data);
				$('#wishlist_recherche .wishlist_container .wishlist_item_container').draggable({
					zIndex:100,
					opacity: 0.80,
					revert:false,
					helper: "clone"
				}).addClass('pointer');
			},
			'html'
		);
	}
}